<?php

namespace app\index\controller;
use think\Controller;
use think\Facade\Request;
use think\Db;
class Login extends Controller
{
    /**
     * 显示登陆页面
     * @return mixed
     */
      public function login()
      {
          return $this->fetch();
      }

    /**
     *处理登陆
     */
      public function doLogin()
      {
          $username = Request::post('username');
          $password = Request::post('password');
          $res = Db::name('user')->where(['username'=>$username,'password'=>$password])->find();
          if($res)
          {
              session('username',$res['username']);
              returnAjax('200','登陆成功');
          }
          returnAjax('201','登陆失败');
      }

    /**
     * 退出登陆
     */
      public function logout()
      {
          session('username',null);
          $this->redirect(url('/login'));
      }
}
